#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    int oddCells(int m, int n, vector<vector<int>> &indices)
    {
        int res = 0;
        vector<vector<int>> matrix(m, vector<int>(n));
        for (auto &index : indices)
        {
            for (int i = 0; i < n; i++)
            {
                // ri 行上的所有单元格，加 1
                matrix[index[0]][i]++;
            }
            for (int i = 0; i < m; i++)
            {
                // ci 列上的所有单元格，加 1
                matrix[i][index[1]]++;
            }
        }
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (matrix[i][j] & 1)
                {
                    res++;
                }
            }
        }
        return res;
    }

     int oddCells_2(int m, int n, vector<vector<int>>& indices) {
        vector<int> rows(m), cols(n);
        for (auto & index : indices) {
            rows[index[0]]++;
            cols[index[1]]++;
        }
        int res = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if ((rows[i] + cols[j]) & 1) {
                    res++;
                }
            }
        }
        return res;
    }

     int oddCells_3(int m, int n, vector<vector<int>>& indices) {
        vector<int> rows(m), cols(n);
        for (auto & index : indices) {
            rows[index[0]]++;
            cols[index[1]]++;
        }
        int oddx = 0, oddy = 0;
        for (int i = 0; i < m; i++) {
            if (rows[i] & 1) {
                oddx++;
            }
        }
        for (int i = 0; i < n; i++) {
            if (cols[i] & 1) {
                oddy++;
            }
        }
        return oddx * (n - oddy) + (m - oddx) * oddy;
    }
};
int main()
{
    Solution s;
    int m = 2, n = 3;
    vector<vector<int>> indices = {{0, 1}, {1, 1}};
    cout << s.oddCells(m, n, indices) << endl;
    system("pause");
    return 0;
}
